#include <iostream>
#include <memory>
#include <vector>
using std::cout;
using std::endl;
using std::vector;
using std::shared_ptr;

class Point
{
public:
    Point(int ix = 0, int iy = 0)
    : _ix(ix)
    , _iy(iy)
    {
        cout << "Point(int,int)" << endl;
    }

    void print() const{
        cout << "(" << _ix
            << "," <<_iy
            << ")" << endl;
    }

    ~Point(){
        cout << "~Point()" << endl;
    }

private:
    int _ix;
    int _iy;
};

void test0(){
    shared_ptr<Point> sp(new Point(1,2));
    shared_ptr<Point> sp1 = sp;
    cout << "sp.use_count " << sp.use_count() << endl;
    cout << "sp1.use_count " << sp1.use_count() << endl;

    cout << sp.get() << endl;
    cout << sp1.get() << endl;

    sp->print();//sp---Point*
    (*sp).print();
}

void test1(){
    shared_ptr<Point> sp2(new Point(8,9));
    shared_ptr<Point> sp3(new Point(1,2));
    sp2 = sp3;

    cout << "sp2.use_count " << sp2.use_count() << endl;
    cout << "sp3.use_count " << sp3.use_count() << endl;

    cout << sp2.get() << endl;
    cout << sp3.get() << endl;

    sp2->print();//sp---Point*
    sp3->print();

}

void test2(){
    shared_ptr<Point> sp2(new Point(8,9));
    shared_ptr<Point> sp3(new Point(1,2));
    vector<shared_ptr<Point>> vec;

    vec.push_back(sp2);
    sp2->print();
    vec[0]->print();
    cout << sp2.use_count() << endl;
    
    vec.push_back(shared_ptr<Point>(new Point(5,6)));
    vec[1]->print();
    
    vec.push_back(std::move(sp3));
    vec[2]->print();
}

int main(int argc, char * argv[])
{
    test2();
    return 0;
}


